package com.inke.box.app;

import android.app.Application;
import android.content.Intent;

import com.blankj.utilcode.util.Utils;
import com.franmontiel.persistentcookiejar.ClearableCookieJar;
import com.franmontiel.persistentcookiejar.PersistentCookieJar;
import com.franmontiel.persistentcookiejar.cache.SetCookieCache;
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor;
import com.inke.box.net.minasocket.InkeMinaClientService;
import com.inke.box.net.minasocket.InkeMinaServer;
import com.orhanobut.hawk.Hawk;
import com.tsy.sdk.myokhttp.MyOkHttp;

import java.util.concurrent.TimeUnit;

import butterknife.ButterKnife;
import okhttp3.OkHttpClient;

/**
 * Created by Administrator on 2017/11/1.
 */

public class InKeBoxApplication extends Application {

    private static MyOkHttp myOkHttp;
    private static InKeBoxApplication inKeBoxApplication;
    @Override
    public void onCreate() {
        super.onCreate();
        inKeBoxApplication = this;
        init();
    }



    private void init() {
        //初始化数据库
        Hawk.init(this).build();
        //初始化工具类
        Utils.init(this);
        initHttpRequest();
        //启动服务器服务
        startService(new Intent(this, InkeMinaServer.class));
        startService(new Intent(this,InkeMinaClientService.class));
    }



    //初始化okHttp3
    private void initHttpRequest() {
        //设置开启cookie
        ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(this));
        //okhttp的配置
        OkHttpClient build = new OkHttpClient().newBuilder().cookieJar(cookieJar).connectTimeout(1000L, TimeUnit.MILLISECONDS).readTimeout(10000L, TimeUnit.MILLISECONDS).build();
        myOkHttp = new MyOkHttp(build);
    }



    public static MyOkHttp getMyOkHttp(){
        return myOkHttp;
    }



    public static InKeBoxApplication getInKeBoxApplication() {
        return inKeBoxApplication;
    }
}
